this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.UI=this.BX.Landing.UI||{};(function(e,t,i,n,a,r,s,l,o,c,u,d,h,g){"use strict";var f,y,p;function v(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}return i}function b(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?v(Object(i),!0).forEach((function(t){babelHelpers.defineProperty(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):v(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function C(e,t){F(e,t);t.add(e)}function F(e,t){if(t.has(e)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}function m(e,t,i){if(!t.has(e)){throw new TypeError("attempted to get private field on non-instance")}return i}var L=new WeakSet;var w=new WeakSet;var k=new WeakSet;var T=new WeakSet;var D=function(e){babelHelpers.inherits(i,e);babelHelpers.createClass(i,null,[{key:"isEditorContext",value:function e(){return i.staticCache.remember("isEditorContext",(function(){var e=r.PageObject.getRootWindow();var i=e.document.body.querySelector(".landing-ui-view");return t.Type.isDomNode(i)}))}},{key:"getRootWindow",value:function e(){return i.staticCache.remember("rootWindow",(function(){if(i.isEditorContext()){return r.PageObject.getRootWindow()}return window}))}},{key:"getInstance",value:function e(t){var n=i.getRootWindow();var a=n.BX.Landing.UI.Panel.FieldsPanel;if(!a.instance&&!i.instance){a.instance=new i(t)}var r=a.instance||i.instance;r.options=t;return r}}]);function i(){var e;var n=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};babelHelpers.classCallCheck(this,i);e=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(i).call(this));C(babelHelpers.assertThisInitialized(e),T);C(babelHelpers.assertThisInitialized(e),k);C(babelHelpers.assertThisInitialized(e),w);C(babelHelpers.assertThisInitialized(e),L);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(e),"adjustActionsPanels",false);e.setEventNamespace("BX.Landing.UI.Panel.FieldsPanel");e.setLayoutClass("landing-ui-panel-fields");e.setOverlayClass("landing-ui-panel-fields-overlay");e.setTitle(l.Loc.getMessage("LANDING_FIELDS_PANEL_TITLE"));e.onSaveClick=e.onSaveClick.bind(babelHelpers.assertThisInitialized(e));e.onCancelClick=e.onCancelClick.bind(babelHelpers.assertThisInitialized(e));e.options=n;e.cache=new t.Cache.MemoryCache;t.Dom.append(e.layout,e.getViewContainer());t.Dom.append(e.overlay,e.getViewContainer());t.Dom.insertAfter(e.getSearchContainer(),e.header);t.Dom.append(e.getCreateFieldLayout(),e.body);e.appendFooterButton(new c.BaseButton("save_settings",{text:l.Loc.getMessage("LANDING_FIELDS_PANEL_ADD_SELECTED_BUTTON"),onClick:e.onSaveClick,className:"landing-ui-button-content-save",attrs:{title:l.Loc.getMessage("LANDING_TITLE_OF_SLIDER_SAVE")}}));e.appendFooterButton(new c.BaseButton("cancel_settings",{text:l.Loc.getMessage("BLOCK_CANCEL"),onClick:e.onCancelClick,className:"landing-ui-button-content-cancel",attrs:{title:l.Loc.getMessage("LANDING_TITLE_OF_SLIDER_CANCEL")}}));return e}babelHelpers.createClass(i,[{key:"isMultiple",value:function e(){return this.cache.get("multiple",true)}},{key:"setMultiple",value:function e(t){this.cache.set("multiple",t)}},{key:"setAllowedTypes",value:function e(t){this.cache.set("allowedTypes",t)}},{key:"getAllowedTypes",value:function e(){return this.cache.get("allowedTypes",[])}},{key:"setDisabledFields",value:function e(t){this.cache.set("disabledFields",t)}},{key:"getDisabledFields",value:function e(){return this.cache.get("disabledFields",[])}},{key:"setAllowedCategories",value:function e(t){this.cache.set("allowedCategories",t)}},{key:"getAllowedCategories",value:function e(){return this.cache.get("allowedCategories",[])}},{key:"setDisabledCategories",value:function e(t){this.cache.set("disabledCategories",t)}},{key:"getDisabledCategories",value:function e(){return this.cache.get("disabledCategories",[])}},{key:"resetFactoriesCache",value:function e(){var t=this;this.cache.keys().forEach((function(e){if(e.startsWith("userFieldFactory_")){t.cache["delete"](e)}}))}},{key:"setLoadOptions",value:function e(t){this.cache.set("loadOptions",b({},t))}},{key:"getLoadOptions",value:function e(){return this.cache.get("loadOptions",{})}},{key:"show",value:function e(){var n,a=this;var r=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};if(m(this,w,B).call(this)){return Promise.resolve()}m(this,L,I).call(this,true);this.getSearchField().input.textContent="";this.setMultiple(true);this.setAllowedTypes([]);this.setDisabledFields([]);this.setAllowedCategories([]);this.setDisabledCategories([]);this.resetFactoriesCache();if(t.Type.isArrayFilled(r.disabledFields)){this.setDisabledFields(r.disabledFields)}if(t.Type.isArrayFilled(r.allowedCategories)){this.setAllowedCategories(r.allowedCategories)}if(t.Type.isArrayFilled(r.disabledCategories)){this.setDisabledCategories(r.disabledCategories)}if(t.Type.isArrayFilled(r.allowedTypes)){this.setAllowedTypes(r.allowedTypes)}if(t.Type.isBoolean(r.multiple)){this.setMultiple(r.multiple)}t.Dom.style(this.layout,"position",(n=r.position)!==null&&n!==void 0?n:null);var l=["hideVirtual","hideRequisites","hideSmartDocument","presetId"];var o=Object.entries(r).reduce((function(e,t){var i=babelHelpers.slicedToArray(t,2),n=i[0],a=i[1];if(l.includes(n)){e[n]=a}return e}),{});this.setLoadOptions(o);this.showLoader();this.load(o).then((function(){a.hideLoader();a.clearSidebar();Object.entries(a.getCrmFields()).forEach((function(e){var i=babelHelpers.slicedToArray(e,2),n=i[0],r=i[1];if(n!=="CATALOG"&&n!=="ACTIVITY"&&n!=="INVOICE"){if(t.Type.isPlainObject(a.options)&&t.Type.isBoolean(a.options.isLeadEnabled)&&!a.options.isLeadEnabled&&n==="LEAD"){return}var l=new s.SidebarButton({id:n,text:r.CAPTION,child:true,onClick:function e(){a.onSidebarButtonClick(l)}});a.appendSidebarButton(l)}}))})).then((function(){var e=a.getFilteredFieldsTree();var i=Object.keys(e);a.sidebarButtons.forEach((function(e){e.deactivate();if(i.includes(e.id)){t.Dom.show(e.getLayout())}else{t.Dom.hide(e.getLayout())}}));if(a.sidebarButtons.length>0){a.resetState();var n=a.sidebarButtons.find((function(e){return e.getLayout().hidden!==true}));if(n){n.getLayout().click()}}}));t.Dom.append(this.overlay,this.layout.parentElement);babelHelpers.get(babelHelpers.getPrototypeOf(i.prototype),"show",this).call(this,r).then((function(){m(a,L,I).call(a,false);a.getSearchField().enableEdit();a.getSearchField().input.focus()}));return new Promise((function(e){a.promiseResolver=e}))}},{key:"hide",value:function e(){this.setCrmFields(this.getOriginalCrmFields());return babelHelpers.get(babelHelpers.getPrototypeOf(i.prototype),"hide",this).call(this)}},{key:"onSaveClick",value:function e(){var t=Object.values(this.getState()).reduce((function(e,t){return[].concat(babelHelpers.toConsumableArray(e),babelHelpers.toConsumableArray(t))}),[]);this.promiseResolver(t);void this.hide();this.resetState()}},{key:"onCancelClick",value:function e(){void this.hide();this.resetState()}},{key:"getViewContainer",value:function e(){return this.cache.remember("viewContainer",(function(){if(i.isEditorContext()){var e=i.getRootWindow();return e.document.querySelector(".landing-ui-view-container")}return document.body}))}},{key:"getLoader",value:function e(){var t=this;return this.cache.remember("loader",(function(){return new n.Loader({target:t.body})}))}},{key:"showLoader",value:function e(){this.hideCreateFieldButton();void this.getLoader().show()}},{key:"hideLoader",value:function e(){this.showCreateFieldButton();void this.getLoader().hide()}},{key:"setHideVirtual",value:function e(t){this.cache.set("hideVirtual",t)}},{key:"getHideVirtual",value:function e(){return this.cache.get("hideVirtual",null)}},{key:"setHideRequisites",value:function e(t){this.cache.set("hideRequisites",t)}},{key:"getHideRequisites",value:function e(){return this.cache.get("hideRequisites",null)}},{key:"setHideSmartDocuments",value:function e(t){this.cache.set("hideSmartDocument",t)}},{key:"getHideSmartDocuments",value:function e(){return this.cache.get("hideSmartDocument",true)}},{key:"load",value:function e(){var t=this;var n=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return a.Backend.getInstance().action("Form::getCrmFields",{options:n}).then((function(e){t.setOriginalCrmFields(e);t.setCrmFields(e);if(i.isEditorContext()){Object.assign(d.FormSettingsPanel.getInstance().getCrmFields(),e)}return h.FormClient.getInstance().getDictionary().then((function(e){t.setFormDictionary(e)}))}))}},{key:"setFormDictionary",value:function e(t){this.cache.set("formDictionary",t)}},{key:"getFormDictionary",value:function e(){return this.cache.get("formDictionary",{})}},{key:"setOriginalCrmFields",value:function e(t){this.cache.set("originalFields",t)}},{key:"getOriginalCrmFields",value:function e(){return this.cache.get("originalFields")||{}}},{key:"setCrmFields",value:function e(t){this.cache.set("fields",t)}},{key:"getCrmFields",value:function e(){return this.cache.get("fields")||{}}},{key:"setState",value:function e(t){this.cache.set("state",t)}},{key:"getState",value:function e(){return this.cache.get("state")||{}}},{key:"resetState",value:function e(){this.cache["delete"]("state")}},{key:"onSidebarButtonClick",value:function e(i){var n=this.sidebarButtons.getActive();if(n){n.deactivate()}i.activate();var a=this.getAllowedTypes().every((function(e){return t.Type.isPlainObject(e)}));if(t.Type.isArrayFilled(this.getAllowedTypes())&&a){this.hideCreateFieldButton()}else{this.showCreateFieldButton()}var r=this.getCrmFields();if(Reflect.has(r,i.id)){this.clearContent();var s=this.createFieldsListForm(i.id);this.appendForm(s)}}},{key:"getFilteredFieldsTree",value:function e(){var i=String(this.getSearchField().getValue()).toLowerCase().trim();var n=this.getAllowedCategories();var a=this.getDisabledCategories();var r=this.getAllowedTypes();return Object.entries(this.getCrmFields()).reduce((function(e,s){var l=babelHelpers.slicedToArray(s,2),o=l[0],c=l[1];if(o!=="CATALOG"&&o!=="ACTIVITY"&&o!=="INVOICE"&&(!t.Type.isArrayFilled(n)||n.includes(o))&&!a.includes(o)){var u=c.FIELDS.filter((function(e){if(e.name==="CONTACT_ORIGIN_VERSION"||e.name==="CONTACT_LINK"){return false}var n=String(e.caption).toLowerCase().trim();if(t.Type.isArrayFilled(r)){var a=r.some((function(i){if(!t.Type.isPlainObject(i)){i={type:i}}if(i.entityFieldName&&i.entityFieldName!==e.entity_field_name){return false}if(t.Type.isBoolean(i.multiple)&&i.multiple!==e.multiple){return false}return e.type===i.type}));if(!a){return false}}return!t.Type.isStringFilled(i)||n.includes(i)}));if(t.Type.isArrayFilled(u)){e[o]=b(b({},c),{},{FIELDS:u})}}return e}),{})}},{key:"createFieldsListForm",value:function e(i){var n=this;var a=this.getFilteredFieldsTree();var r=this.getDisabledFields();var s={items:a[i].FIELDS.map((function(e){return{name:e.caption,value:e.name,disabled:t.Type.isArrayFilled(r)&&r.includes(e.name)}})),value:this.getState()[i]||[],onValueChange:function e(t){var a=b({},n.getState());a[i]=t.getValue();n.setState(a)}};return new o.FormSettingsForm({fields:[this.isMultiple()?new BX.Landing.UI.Field.Checkbox(s):new BX.Landing.UI.Field.Radio(s)]})}},{key:"onSearchChange",value:function e(){var i=this.getFilteredFieldsTree();var n=Object.keys(i);this.sidebarButtons.forEach((function(e){e.deactivate();if(n.includes(e.id)){t.Dom.show(e.getLayout())}else{t.Dom.hide(e.getLayout())}}));this.clearContent();var a=n[0];if(a){var r=this.sidebarButtons.get(a);if(r){r.activate()}var s=this.createFieldsListForm(a);this.showCreateFieldButton();this.appendForm(s)}else{this.hideCreateFieldButton()}}},{key:"getSearchField",value:function e(){var t=this;return this.cache.remember("searchField",(function(){var e=i.getRootWindow();return new e.BX.Landing.UI.Field.Text({selector:"search",textOnly:true,placeholder:l.Loc.getMessage("LANDING_FIELDS_PANEL_SEARCH"),onChange:t.onSearchChange.bind(t)})}))}},{key:"getSearchContainer",value:function e(){var i=this;return this.cache.remember("searchLayout",(function(){return t.Tag.render(f||(f=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="landing-ui-panel-content-element landing-ui-panel-content-search">\n\t\t\t\t\t','\n\t\t\t\t\t<div class="landing-ui-panel-content-search-icon"></div>\n\t\t\t\t</div>\n\t\t\t'])),i.getSearchField().getLayout())}))}},{key:"getUserFieldFactory",value:function e(i){var n=this;var a=this.cache.remember("userFieldFactory_".concat(i),(function(){var e=window.top;var t=function(){if(i.startsWith("DYNAMIC_")){return n.getCrmFields()[i].DYNAMIC_ID}return"CRM_".concat(i)}();var a=function(){if(e.BX.UI.UserFieldFactory){return e.BX.UI.UserFieldFactory.Factory}return BX.UI.UserFieldFactory.Factory}();return new a(t,{moduleId:"crm",bindElement:n.getCreateFieldButton()})}));if(t.Type.isArrayFilled(this.getAllowedTypes())){a.types=a.types.filter((function(e){return n.getAllowedTypes().includes(e.name)}))}else{a.types=a.types.filter((function(e){return e.name!=="employee"}))}return a}},{key:"onCreateFieldClick",value:function e(n){var a=this;n.preventDefault();var r=this.getFormDictionary();if(t.Type.isPlainObject(r.permissions)&&t.Type.isPlainObject(r.permissions.userField)&&r.permissions.userField.add===false){var s=i.getRootWindow();s.BX.UI.Dialogs.MessageBox.alert(l.Loc.getMessage("LANDING_FORM_ADD_USER_FIELD_PERMISSION_DENIED"));return}var o=this.sidebarButtons.getActive();var c=o.id;var u=this.getUserFieldFactory(c);var d=u.getMenu();d.open((function(e){var i=u.getConfigurator({userField:u.createUserField(e),onSave:function e(t){t.save().then((function(){return a.load(a.getLoadOptions())})).then((function(){a.getSearchField().setValue(t.getData().editFormLabel[l.Loc.getMessage("LANGUAGE_ID")]);a.showCreateFieldButton()}))},onCancel:function e(){a.showCreateFieldButton();a.sidebarButtons.getActive().getLayout().click()}});a.clearContent();t.Dom.append(i.render(),a.content);a.hideCreateFieldButton()}));t.Dom.style(d.getPopup().getPopupContainer(),"z-index",9999)}},{key:"getCreateFieldButton",value:function e(){var i=this;return this.cache.remember("getCreateFieldButton",(function(){return t.Tag.render(y||(y=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div\n\t\t\t\t\tclass="landing-ui-panel-content-create-field-button"\n\t\t\t\t\tonclick="','"\n\t\t\t\t>\n\t\t\t\t\t',"\n\t\t\t\t</div>\n\t\t\t"])),i.onCreateFieldClick.bind(i),l.Loc.getMessage("LANDING_FIELDS_PANEL_CREATE_FIELD"))}))}},{key:"getCreateFieldLayout",value:function e(){var i=this;return this.cache.remember("createFieldLayout",(function(){return t.Tag.render(p||(p=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="landing-ui-panel-content-create-field">\n\t\t\t\t\t',"\n\t\t\t\t</div>\n\t\t\t"])),i.getCreateFieldButton())}))}},{key:"isUserFieldEditorShowed",value:function e(){return t.Type.isDomNode(this.content.querySelector(".ui-userfieldfactory-configurator"))}},{key:"showCreateFieldButton",value:function e(){t.Dom.append(this.getCreateFieldLayout(),this.body)}},{key:"hideCreateFieldButton",value:function e(){t.Dom.remove(this.getCreateFieldLayout(),this.body)}}]);return i}(i.Content);function I(e){this.cache.set("showLock",e)}function B(){return this.cache.get("showLock",false)}babelHelpers.defineProperty(D,"staticCache",new t.Cache.MemoryCache);e.FieldsPanel=D})(this.BX.Landing.UI.Panel=this.BX.Landing.UI.Panel||{},BX,BX.Landing.UI.Panel,BX,BX.Landing,BX.Landing,BX.Landing.UI.Button,BX.Landing,BX.Landing.UI.Form,BX.Landing.UI.Button,BX.Landing.UI.Field,BX.Landing.UI.Panel,BX.Crm.Form,BX);
//# sourceMappingURL=fieldspanel.bundle.map.js